package com.wtgroup.demo.mianshi.测试开发;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/3/11 12:23
 */
public class Case01_ParallelIsPrime {

    static List<Integer> nums = new ArrayList<>();

    static {
        Random r = new Random();
        for (int i = 0; i < 1000; i++) {
            nums.add(100_0000 + r.nextInt(100_0000));
        }
    }

    static void foreach() {
        nums.forEach(v -> isPrime(v));
    }

    static void parallel() {
        nums.parallelStream().forEach(v -> isPrime(v));
    }

    static boolean isPrime(Integer num) {
        int m = num / 2;
        for (int i = 2; i <= m; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
